In [1]:
import numpy as np

ndarray


In [7]:
array = np.arange(15)
shape = array.reshape(3, 5)
shape


Out[7]:
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])

ndarray.shape: the dimension of the array


In [8]:
shape.shape


Out[8]:
(3, 5)

ndarray.ndim: the number of axes (dimensions) of the array


In [9]:
shape.ndim


Out[9]:
2

Array Creation


In [12]:
np.array([2,3,4])


Out[12]:
array([2, 3, 4])

In [11]:
np.array([(1.5,2,3), (4,5,6)])


Out[11]:
array([[ 1.5,  2. ,  3. ],
       [ 4. ,  5. ,  6. ]])

In [13]:
np.zeros( (3,4) )


Out[13]:
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])

In [14]:
np.ones( (2,3,4), dtype=np.int16 )


Out[14]:
array([[[1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1]],

       [[1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1]]], dtype=int16)

In [15]:
np.arange( 10, 30, 5 ) # a sequence of number: start, end, step


Out[15]:
array([10, 15, 20, 25])

In [17]:
np.arange( 0, 2, 0.3 ) # float


Out[17]:
array([ 0. ,  0.3,  0.6,  0.9,  1.2,  1.5,  1.8])

In [16]:
np.linspace( 0, 2, 9 ) # 9 numbers from 0 to 2


Out[16]:
array([ 0.  ,  0.25,  0.5 ,  0.75,  1.  ,  1.25,  1.5 ,  1.75,  2.  ])

In [ ]: